<template>
    <Upload ref="upload" action="/api/upload/file" 
    :default-file-list="defaultList" :on-remove="handleRemove" :on-success="handleSuccess" :max-size="8000">
        <Button type="ghost" icon="ios-cloud-upload-outline">上传文件</Button>
    </Upload>
</template>
<script>
    export default {
        name: 'UploadedList',
        props: {
            value: {
                type: Array
            }
        },
        data () {
            return {
            }
        },
        computed: {
            defaultList() {
                return this.value;
            }
        },
        methods: {
            handleSuccess (res, file) {
                if(res.list.length > 0) this.value.push(res.list[0]);
            },
            handleRemove (file) {
                const fileList = this.$refs.upload.fileList;
                var index = fileList.indexOf(file);
                this.api.post("upload/delete", { id: file.id }, res => {
                    this.value.splice(index, 1);
                });
            }
        },
        created() {
        }
    }
</script>
